#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>

int main(int argc, char const *argv[])
{
    int fd[2];
    pipe(fd);
    //fd[0] 读端
    //fd[1] 写端

    int var;
    pid_t pid = fork();
    if (pid == 0)
    {
        while(1)
        {
            printf("请输入一个整数：");
            scanf("%d", &var);
            write(fd[1],&var,sizeof(var));
            sleep(1);
        }
    }
    else
    {
        while(1)
        {
            read(fd[0],&var,sizeof(var));
            printf("%d\n", var);
            sleep(1);
        }
    }
    return 0;
}
